{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 外层表示循环次数，没循环一次产生一个结果，最后一个没有需要比较的，所以只需要 n -1 次\n",
    "- 内层循环表示冒泡过程，由于需要和后一位比较，所以最后一位需要忽略"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-25T12:23:00.736317Z",
     "start_time": "2024-10-25T12:23:00.727332Z"
    }
   },
   "source": [
    "\n",
    "def sort(arr):\n",
    "    for a in range(1,len(arr)):\n",
    "        for b in range(0,len(arr) - a -1):\n",
    "            if(arr[b] > arr[b+1]):\n",
    "                arr[b],arr[b+1] = arr[b+1],arr[b]\n",
    "\n",
    "\n",
    "arr = [3,2,5,9,6,7,2]\n",
    "sort(arr)\n",
    "arr"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 5, 6, 7, 9, 2]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
